/*
 * @Author: heinan
 * @Date: 2023-08-09 16:12:31
 * @Last Modified by: heinan
 * @Last Modified time: 2023-08-09 20:52:00
 */

"use strict";
const { Controller } = require("egg");

/**
 *  @Controller 意见反馈
 */
class FeedBackController extends Controller {
  /**
   * @Summary 意见反馈列表接口
   * @Description 获取意见反馈分页列表
   * @Router GET /api/v1/feedback
   * @Request query Number currentPage 页码 默认 1
   * @Request query Number pageSize 单页数量 默认 20
   */
  async index() {
    const result = await this.ctx.service.feedback.index(this.ctx.query);
    if (result.data.length) {
      this.ctx.body = {
        code: 1,
        message: "查询成功!",
        data: result,
      };
    } else {
      this.ctx.body = {
        code: 0,
        message: "暂无数据!",
        data: [],
      };
    }
  }
  /**
   * @Summary 添加意见反馈接口
   * @Description 添加意见反馈接口
   * @Router POST /api/v1/feedback
   * @Request body createFeedBack *body
   */
  async create() {
    const result = await this.ctx.service.feedback.create(
      this.ctx.request.body
    );
    if (result.affectedRows) {
      this.ctx.body = {
        code: 1,
        message: "新增成功!",
      };
    } else {
      this.ctx.body = {
        code: 0,
        message: "新增失败!",
      };
    }
  }
  /**
   * @Summary 更新意见反馈接口
   * @Description 根据团购数据id,接口更新团购数据状态
   * @Router PUT /api/v1/feedback/{id}
   * @Request path string *id
   * @Request body updateFeedBack *body
   */
  async update() {
    const result = await this.ctx.service.feedback.update({
      ...this.ctx.params,
      ...this.ctx.request.body,
    });
    if (result.affectedRows) {
      this.ctx.body = {
        code: 1,
        message: "修改成功!",
      };
    } else {
      this.ctx.body = {
        code: 0,
        message: "修改失败!",
      };
    }
  }
  /**
   * @Summary 删除意见反馈接口
   * @Description 根据反馈id删除意见
   * @Router DELETE /api/v1/feedback/{id}
   * @Request path string *id
   */
  async destroy() {
    const result = await this.ctx.service.feedback.destroy(this.ctx.params);
    if (result.affectedRows) {
      this.ctx.body = {
        code: 1,
        message: "删除成功!",
      };
    } else {
      this.ctx.body = {
        code: 0,
        message: "删除失败!",
      };
    }
  }
}

module.exports = FeedBackController;
